package com.itheima.sc.impl.ums;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.sc.api.ums.UmsRoleResourceRelationApi;
import com.itheima.sc.mapper.ums.UmsRoleResourceRelationMapper;
import com.itheima.sc.pojo.ums.UmsRoleResourceRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsRoleResourceRelationImpl implements UmsRoleResourceRelationApi {
    @Autowired
    private UmsRoleResourceRelationMapper umsRoleResourceRelationMapper;

    /**
     * 根据roleId查询role_resource关系表
     */
    @Override
    public List<UmsRoleResourceRelation> roleResourceList(Integer roleId) {
        //构建查询条件
        LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);

        //查询数据
        return umsRoleResourceRelationMapper.selectList(wrapper);
    }

    /**
     * 将原来的数据删除
     */
    @Override
    public void delete(Integer roleId) {
        LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);
        umsRoleResourceRelationMapper.delete(wrapper);
    }
}
